{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f51237b1-8971-48c7-bd38-89cfc6347323",
   "metadata": {},
   "source": [
    "jupyter notebook 工具有两个模式\n",
    "markdown模式是笔记模式。\n",
    "code模式是代码模式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "789779cd-0f8f-4618-bc58-75821db5c08a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《戴你玩转数据分析》_职场新人_18-24_1-6',\n",
       "  '广告计划ID': 'AD666',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 88,\n",
       "  '消耗': 2245,\n",
       "  '直播间曝光数': 5893,\n",
       "  '直播间观看数': 2298,\n",
       "  '商品点击数': 1654,\n",
       "  '商品下单数': 160,\n",
       "  '商品成交数': 14,\n",
       "  'GMV': 123200,\n",
       "  '成交金额': 123200,\n",
       "  '投放日期': '2023-01-01'},\n",
       " {'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《商业分析课程》_数据分析-商业分析_22-35_1-6',\n",
       "  '广告计划ID': 'AD888',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 288,\n",
       "  '消耗': 3231,\n",
       "  '直播间曝光数': 3274,\n",
       "  '直播间观看数': 1702,\n",
       "  '商品点击数': 1174,\n",
       "  '商品下单数': 102,\n",
       "  '商品成交数': 10,\n",
       "  'GMV': 288000,\n",
       "  '成交金额': 288000,\n",
       "  '投放日期': '2023-01-01'},\n",
       " {'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6',\n",
       "  '广告计划ID': 'AD999',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 188,\n",
       "  '消耗': 3784,\n",
       "  '直播间曝光数': 5865,\n",
       "  '直播间观看数': 4633,\n",
       "  '商品点击数': 2779,\n",
       "  '商品下单数': 200,\n",
       "  '商品成交数': 27,\n",
       "  'GMV': 507600,\n",
       "  '成交金额': 507600,\n",
       "  '投放日期': '2023-01-01'}]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[{'投放账户': '戴戴戴师兄', '广告计划名称': '《戴你玩转数据分析》_职场新人_18-24_1-6', '广告计划ID': 'AD666', '优化目标': '直播间成交', '客单价': 88, '消耗': 2245, '直播间曝光数': 5893, '直播间观看数': 2298, '商品点击数': 1654, '商品下单数': 160, '商品成交数': 14, 'GMV': 123200, '成交金额': 123200, '投放日期': '2023-01-01'}, {'投放账户': '戴戴戴师兄', '广告计划名称': '《商业分析课程》_数据分析-商业分析_22-35_1-6', '广告计划ID': 'AD888', '优化目标': '直播间成交', '客单价': 288, '消耗': 3231, '直播间曝光数': 3274, '直播间观看数': 1702, '商品点击数': 1174, '商品下单数': 102, '商品成交数': 10, 'GMV': 288000, '成交金额': 288000, '投放日期': '2023-01-01'}, {'投放账户': '戴戴戴师兄', '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6', '广告计划ID': 'AD999', '优化目标': '直播间成交', '客单价': 188, '消耗': 3784, '直播间曝光数': 5865, '直播间观看数': 4633, '商品点击数': 2779, '商品下单数': 200, '商品成交数': 27, 'GMV': 507600, '成交金额': 507600, '投放日期': '2023-01-01'}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cfc87acf-5658-4df2-ad61-db4e359baa3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "ad_list=[{'投放账户': '戴戴戴师兄', '广告计划名称': '《戴你玩转数据分析》_职场新人_18-24_1-6', '广告计划ID': 'AD666', '优化目标': '直播间成交', '客单价': 88, '消耗': 2245, '直播间曝光数': 5893, '直播间观看数': 2298, '商品点击数': 1654, '商品下单数': 160, '商品成交数': 14, 'GMV': 123200, '成交金额': 123200, '投放日期': '2023-01-01'}, {'投放账户': '戴戴戴师兄', '广告计划名称': '《商业分析课程》_数据分析-商业分析_22-35_1-6', '广告计划ID': 'AD888', '优化目标': '直播间成交', '客单价': 288, '消耗': 3231, '直播间曝光数': 3274, '直播间观看数': 1702, '商品点击数': 1174, '商品下单数': 102, '商品成交数': 10, 'GMV': 288000, '成交金额': 288000, '投放日期': '2023-01-01'}, {'投放账户': '戴戴戴师兄', '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6', '广告计划ID': 'AD999', '优化目标': '直播间成交', '客单价': 188, '消耗': 3784, '直播间曝光数': 5865, '直播间观看数': 4633, '商品点击数': 2779, '商品下单数': 200, '商品成交数': 27, 'GMV': 507600, '成交金额': 507600, '投放日期': '2023-01-01'}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2a3078da-e119-4cf5-b4f6-9bc082be5055",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《戴你玩转数据分析》_职场新人_18-24_1-6',\n",
       "  '广告计划ID': 'AD666',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 88,\n",
       "  '消耗': 2245,\n",
       "  '直播间曝光数': 5893,\n",
       "  '直播间观看数': 2298,\n",
       "  '商品点击数': 1654,\n",
       "  '商品下单数': 160,\n",
       "  '商品成交数': 14,\n",
       "  'GMV': 123200,\n",
       "  '成交金额': 123200,\n",
       "  '投放日期': '2023-01-01'},\n",
       " {'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《商业分析课程》_数据分析-商业分析_22-35_1-6',\n",
       "  '广告计划ID': 'AD888',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 288,\n",
       "  '消耗': 3231,\n",
       "  '直播间曝光数': 3274,\n",
       "  '直播间观看数': 1702,\n",
       "  '商品点击数': 1174,\n",
       "  '商品下单数': 102,\n",
       "  '商品成交数': 10,\n",
       "  'GMV': 288000,\n",
       "  '成交金额': 288000,\n",
       "  '投放日期': '2023-01-01'},\n",
       " {'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6',\n",
       "  '广告计划ID': 'AD999',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 188,\n",
       "  '消耗': 3784,\n",
       "  '直播间曝光数': 5865,\n",
       "  '直播间观看数': 4633,\n",
       "  '商品点击数': 2779,\n",
       "  '商品下单数': 200,\n",
       "  '商品成交数': 27,\n",
       "  'GMV': 507600,\n",
       "  '成交金额': 507600,\n",
       "  '投放日期': '2023-01-01'}]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ad_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f06900fc-fc71-42c9-a456-6f2ee4ccecd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "menu1=\"蒸乌鱼\"\n",
    "menu2=\"蒸鳄心\"\n",
    "menu3=\"蒸虾头\"\n",
    "menu4=\"蒸梅酥芝\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f9261d4d-2148-4dca-beae-ceb8f74a94c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "menu_list=[\"蒸乌鱼\",\"蒸鳄心\",\"蒸虾头\",\"蒸梅酥芝\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "afc41a7e-35dd-481d-9d78-651788bb56a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['蒸乌鱼', '蒸鳄心', '蒸虾头', '蒸梅酥芝']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "menu_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1a9b3bc-ed08-49c9-aebd-1e7b0013effe",
   "metadata": {},
   "outputs": [],
   "source": [
    "{\"油饼\":[\"22\",\"34\",\"55\"]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "fe02daaa-206b-4542-8f9a-15074bba8647",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'蒸乌鱼'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "menu_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f6dee17f-0c95-4e1e-827a-7f783dca3116",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['蒸乌鱼', '蒸鳄心', '蒸虾头', '蒸梅酥芝']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "menu_list[0:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a2c0283-afdf-4eff-bbbb-093ef6f26b50",
   "metadata": {},
   "source": [
    "首先进行清洗数据，指的是对数据进行预处理，解决数据中格式不规范等问题，方便后续数据的应用。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65555f55-bdb2-4d99-9e95-aa016036f433",
   "metadata": {},
   "source": [
    "1、取出数据，并赋值给一个变量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "ec13567b-d6ac-4c44-bbb1-973f31471c9c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'投放账户': '戴戴戴师兄',\n",
       " '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6',\n",
       " '广告计划ID': 'AD999',\n",
       " '优化目标': '直播间成交',\n",
       " '客单价': 188,\n",
       " '消耗': 3784,\n",
       " '直播间曝光数': 5865,\n",
       " '直播间观看数': 4633,\n",
       " '商品点击数': 2779,\n",
       " '商品下单数': 200,\n",
       " '商品成交数': 27,\n",
       " 'GMV': 507600,\n",
       " '成交金额': 507600,\n",
       " '投放日期': '2023-01-01'}"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ad_1=ad_list[2]\n",
    "ad_1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8461a8bb-718f-4bb5-b450-e6b1d610e08d",
   "metadata": {
    "jp-MarkdownHeadingCollapsed": true
   },
   "source": [
    " 2、处理重复的字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "80f855db-e818-4fe5-a0af-f888f3f688cf",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "del ad_1['成交金额']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "050f9362-af2c-40bb-8a9d-83bb2d3dc395",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'投放账户': '戴戴戴师兄',\n",
       " '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6',\n",
       " '广告计划ID': 'AD999',\n",
       " '优化目标': '直播间成交',\n",
       " '客单价': 188,\n",
       " '消耗': 3784,\n",
       " '直播间曝光数': 5865,\n",
       " '直播间观看数': 4633,\n",
       " '商品点击数': 2779,\n",
       " '商品下单数': 200,\n",
       " '商品成交数': 27,\n",
       " 'GMV': 507600,\n",
       " '投放日期': '2023-01-01'}"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ad_1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2cb6c03-caa5-4f12-9225-226cbf1661ac",
   "metadata": {},
   "source": [
    "3、处理异常数值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "504098c6-84c2-49d0-ad21-08e0f8da83ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "ad_1[\"GMV\"]=ad_1[\"GMV\"]/100"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ddce2c6-bedd-4ea0-ab2c-892b2a9bff46",
   "metadata": {},
   "source": [
    "4、ROI。ROI是成交额除以成本得到的，用来了解回报是否超过投入成本。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "74b5a316-7242-4d5d-b5b3-3fd783c71075",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'投放账户': '戴戴戴师兄',\n",
       " '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6',\n",
       " '广告计划ID': 'AD999',\n",
       " '优化目标': '直播间成交',\n",
       " '客单价': 188,\n",
       " '消耗': 3784,\n",
       " '直播间曝光数': 5865,\n",
       " '直播间观看数': 4633,\n",
       " '商品点击数': 2779,\n",
       " '商品下单数': 200,\n",
       " '商品成交数': 27,\n",
       " 'GMV': 5076.0,\n",
       " '投放日期': '2023-01-01',\n",
       " 'roi': 1.34}"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ad_1[\"roi\"]=round(ad_1[\"GMV\"]/ad_1[\"消耗\"],2)\n",
    "ad_1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b7da70d-7938-41b5-9be4-5583d7036405",
   "metadata": {},
   "source": [
    "5、广告策略"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "8a41ea0c-7c56-4a1c-8a57-676c5f3efd85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['《数据分析工具课程》', '数据分析', '22-35', '1-6']"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ad_1[\"广告计划名称\"].split(\"_\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "b60f7c5b-5bc0-485e-83c8-f7278388dca3",
   "metadata": {},
   "outputs": [],
   "source": [
    "ad_1[\"商品名称\"]=ad_1[\"广告计划名称\"].split(\"_\")[0]\n",
    "ad_1[\"人群标签\"]=ad_1[\"广告计划名称\"].split(\"_\")[1]\n",
    "ad_1[\"用户年龄\"]=ad_1[\"广告计划名称\"].split(\"_\")[2]\n",
    "ad_1[\"用户等级\"]=ad_1[\"广告计划名称\"].split(\"_\")[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "d1f95deb-f3ad-43de-8d5d-ad518b8089e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'投放账户': '戴戴戴师兄',\n",
       " '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6',\n",
       " '广告计划ID': 'AD999',\n",
       " '优化目标': '直播间成交',\n",
       " '客单价': 188,\n",
       " '消耗': 3784,\n",
       " '直播间曝光数': 5865,\n",
       " '直播间观看数': 4633,\n",
       " '商品点击数': 2779,\n",
       " '商品下单数': 200,\n",
       " '商品成交数': 27,\n",
       " 'GMV': 5076.0,\n",
       " '投放日期': '2023-01-01',\n",
       " 'roi': 1.34,\n",
       " '商品名称': '《数据分析工具课程》',\n",
       " '人群标签': '数据分析',\n",
       " '用户年龄': '22-35',\n",
       " '用户等级': '1-6'}"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ad_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "811efc34-74c4-4695-a143-f95338b7bf5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《戴你玩转数据分析》_职场新人_18-24_1-6',\n",
       "  '广告计划ID': 'AD666',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 88,\n",
       "  '消耗': 2245,\n",
       "  '直播间曝光数': 5893,\n",
       "  '直播间观看数': 2298,\n",
       "  '商品点击数': 1654,\n",
       "  '商品下单数': 160,\n",
       "  '商品成交数': 14,\n",
       "  'GMV': 1232.0,\n",
       "  '投放日期': '2023-01-01',\n",
       "  'roi': 0.55,\n",
       "  '商品名称': '《戴你玩转数据分析》',\n",
       "  '人群标签': '职场新人',\n",
       "  '用户年龄': '18-24',\n",
       "  '用户等级': '1-6'},\n",
       " {'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《商业分析课程》_数据分析-商业分析_22-35_1-6',\n",
       "  '广告计划ID': 'AD888',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 288,\n",
       "  '消耗': 3231,\n",
       "  '直播间曝光数': 3274,\n",
       "  '直播间观看数': 1702,\n",
       "  '商品点击数': 1174,\n",
       "  '商品下单数': 102,\n",
       "  '商品成交数': 10,\n",
       "  'GMV': 2880.0,\n",
       "  '投放日期': '2023-01-01',\n",
       "  'roi': 0.89,\n",
       "  '商品名称': '《商业分析课程》',\n",
       "  '人群标签': '数据分析-商业分析',\n",
       "  '用户年龄': '22-35',\n",
       "  '用户等级': '1-6'},\n",
       " {'投放账户': '戴戴戴师兄',\n",
       "  '广告计划名称': '《数据分析工具课程》_数据分析_22-35_1-6',\n",
       "  '广告计划ID': 'AD999',\n",
       "  '优化目标': '直播间成交',\n",
       "  '客单价': 188,\n",
       "  '消耗': 3784,\n",
       "  '直播间曝光数': 5865,\n",
       "  '直播间观看数': 4633,\n",
       "  '商品点击数': 2779,\n",
       "  '商品下单数': 200,\n",
       "  '商品成交数': 27,\n",
       "  'GMV': 5076.0,\n",
       "  '投放日期': '2023-01-01',\n",
       "  'roi': 1.34,\n",
       "  '商品名称': '《数据分析工具课程》',\n",
       "  '人群标签': '数据分析',\n",
       "  '用户年龄': '22-35',\n",
       "  '用户等级': '1-6'}]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ad_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c13fabe9-efa8-43a4-be73-48f338c8fb0f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
